package com.chen.controller;

import com.chen.pojo.Court;
import com.chen.pojo.Type;
import com.chen.service.court.CourtService;
import com.chen.service.type.TypeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class IndexController {

    @Resource
    private TypeService typeService;

    @Resource
    private CourtService courtService;

    @RequestMapping("/index.html")
    public String index(Model model){
        //查询球场类型列表的方法
        List<Type> typeList = typeService.queryAllType(null);
        //查询南区列表
        List<Court> courtListSouth = courtService.findCourtByAddress("南区", 4);
        //查询北区列表
        List<Court> courtListNorth = courtService.findCourtByAddress("北区", 4);
        //查询体育馆列表
        List<Court> courtListSport = courtService.findCourtByAddress("中心场馆", 4);

        //将数据放到模型里面
        model.addAttribute("typeList",typeList);
        model.addAttribute("courtListSouth",courtListSouth);
        model.addAttribute("courtListNorth",courtListNorth);
        model.addAttribute("courtListSport",courtListSport);
        model.addAttribute("timeId",0);
        model.addAttribute("campus","null");
        return  "forward:/home.jsp";
    }
}
